﻿using Microsoft.AspNetCore.Mvc;
using Ongoal.Quotation;
using Ongoal.Quotation.Service.Interface;
using Ongoal.Quotation.Service.Model.Sys;

namespace Ongoal.Quotation.WebAPI.Controllers
{

    /// <summary>
    /// 代码获取接口
    /// </summary>
    //[Route("Code")]
    public class CodeController : WebAPIBase
    {
        /// <summary>
        /// 服务实现
        /// </summary>
        private ICodeService _service;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="service"></param>
        public CodeController(ICodeService service)
        {
            _service = service;
        }
        /// <summary>
        /// 获取表的数据集合
        /// </summary>
        /// <param name="codeStr">表名（区分大小写）</param>
        /// <returns>数据集合</returns>
        /// <exception cref="ArgumentException"></exception>
        [HttpGet]
        public Dictionary<string, List<dynamic>> GetCode(string codeStr)
        {
            if (string.IsNullOrEmpty(codeStr))
            {
                return new Dictionary<string, List<dynamic>>();
            }

            return _service.GetCode(codeStr);
        }



        /// <summary>
        /// 开发调试预留
        /// </summary>
        /// <returns>测试结果</returns>
        /// <exception cref="ArgumentException"></exception>
        [HttpGet("Test")]
        public string Test()
        {
            return this.Service.SendRequest("/Produce/Material/Get", HttpMethod.Get, null);
        }

        #region 外键
        /// <summary>
        /// 获取外键的数据集合
        /// </summary>
        /// <param name="ModelList">外键参数集合</param>
        /// <returns>数据集合</returns>
        /// <exception cref="ArgumentException"></exception>
        [HttpPost]
        public Dictionary<string, List<dynamic>> GetCode_Foreign([FromBody] List<T_Sys_Interfacesettings> ModelList)
        {
            if (ModelList != null && ModelList.Count > 0)
            {
                return _service.GetCode_Foreign(ModelList);
            }
            return new Dictionary<string, List<dynamic>>();
            
        }
        #endregion
    }
}
